--[[
战斗场景
]]
local FightController = require("app.controllers.FightController")
local BaseScene = require("engin.mvcs.view.BaseScene")
local FightScene = class("FightScene", BaseScene)





	
function FightScene:ctor(param)
	local levelData = param.levelData;
	
	--param.sceneSound = GameSoundProperties[levelData.sceneSound](); --GameSoundProperties.bg_sound();
	param.backgroundImageName = levelData.backgroundImageName;
	param.parallax = levelData.parallax;--远景 近景
	--param.width = levelData.width;
	--param.height = display.height;
	param.batchNodeImage = levelData.batchNodeImage;
	param.touchEnabled = false
	FightScene.super.ctor(self,param)
    
    
    
    local backgroundLayer = self:getBackgroundLayer();
    cc.FileUtils:getInstance():addSearchPath("res/fight/")
  	local node = cc.uiloader:load("fight/Fight.csb"):addTo(backgroundLayer)
	node:setContentSize(cc.size(display.width,display.height));
	ccui.Helper:doLayout(node)
	
	
	
	--[[
    --添加背景
    local backgroundLayer = self:getBackgroundLayer();
    local bgUpHeight = display.height*2/9;
	--背景下面图片
    local background_down =display.newSprite("map/background_down.png");
    backgroundLayer:addChild(background_down);
    local background_down_size = background_down:getContentSize();
    background_down:setPosition(display.cx,(display.height-bgUpHeight)/2);
	background_down:setScaleX( display.width/background_down_size.width)
	background_down:setScaleY((display.height-bgUpHeight)/background_down_size.height)
	--背景上面图片
    local background_up =display.newSprite("map/background_up.png");
    backgroundLayer:addChild(background_up);
    local background_up_size = background_up:getContentSize();
    background_up:setPosition(display.cx,(display.height-bgUpHeight/2));
    background_up:setScaleX( display.width/background_up_size.width)
	background_up:setScaleY(bgUpHeight/background_up_size.height)
   	]]
   	
   	
   	self:init(levelData);
end






function FightScene:init(levelData)
	FightController.getInstance():init(self,levelData);
	
	
	--初始化数据
	local model = FightController.getInstance().model_;
	local energyFullNums = model.fightAccount_.energyFullNums_;
	local energyNums = model.fightAccount_.energyNums_;
	
	local LoadingBar_energyFullNums = cc.uiloader:seekNodeByName(self, "LoadingBar_energyFullNums");
	LoadingBar_energyFullNums:setPercent(0)
	--GameCoreManager:dispatchEvent({name=EventConstants.CurrentEnergysFull,data = self.m_currentEnergys_ })
	GameCoreManager:addEventListener(EventConstants.CurrentEnergysFull, function(event)
		 --local diffitime = os.difftime(os.time(), model.fightAccount_.time_) /60%60;
		 --local percent = diffitime*100/energyFullNums;
		 --echoj("时间：：",diffitime,energyFullNums);
		
		 local percent = model.fightAccount_.m_currentEnergyFullNums_/model.fightAccount_.energyFullNums_;
         LoadingBar_energyFullNums:setPercent(percent * 100)
	end)
	
	
	local LoadingBar_energyNums = cc.uiloader:seekNodeByName(self, "LoadingBar_energyNums");
	LoadingBar_energyNums:setPercent(0)
 	GameCoreManager:addEventListener(EventConstants.CurrentEnergys, function(event)
          local percent = event.data/energyNums;
          LoadingBar_energyNums:setPercent(percent*90);
          --[[
          	if self.destoryCards_ > self.levelConditionParam1_ and
     		os.difftime(os.time(), self.time_) /60%60 <  self.energyFullNums_
     		]]
    end)
    
    
	
	local Button_pause = cc.uiloader:seekNodeByName(self, "Button_pause");
	Button_pause:addTouchEventListener(handler(self,self.pauseHandle))
	
	--总分数
	local targetScore = model.fightAccount_.levelConditionParam1_;
	local Text_targetScore = AtlasText.create({labelWithString = targetScore});
	self:addChild(Text_targetScore);
	Text_targetScore:setAnchorPoint( cc.p(0, 0.5) )
	Text_targetScore:setPosition(display.cx-40,display.top-36);
	
	--当前分数
	local destoryCards = model.fightAccount_.destoryCards_;
	local Text_currentScore = AtlasText.create({labelWithString = destoryCards,
	itemHeight = 45,itemWidth = 39.8,
	charMapFile = "font/UI_mubiaofenshu_shuzi_02.png"});
	self:addChild(Text_currentScore);
	Text_currentScore:setAnchorPoint( cc.p(0, 0.5) )
	Text_currentScore:setPosition(display.cx-40,display.top-202);
  	GameCoreManager:addEventListener(EventConstants.DestoryCards, function(event)
           Text_currentScore:setString(event.data);
     end)
	--[[
	local FightSceneUI = require("app.views.FightSceneUI");
	local fightSceneUI = FightSceneUI.new();
	fightSceneUI:initView(FightController.getInstance().model_);
	self.flysLayer_:addChild(fightSceneUI);
	]]
	
	--[[
	--添加暂停开始的ui
	local StartUI = require("app.views.StartUI");
	local startUI = StartUI.new(nil,self);
	startUI:initView();
	PopUpManager:addPopUp(startUI,nil,true,true)
	]]
end


















--暂停
function FightScene:pauseHandle(sender,eventType)
	if eventType == ccui.TouchEventType.ended then
		FightController.getInstance():play();
	end
end




function FightScene:tick(dt)
	FightScene.super.tick(self,dt);
	
	FightController.getInstance():tick(dt);
end






return FightScene
